// JavaScript Document
var _wrapper = "", _window = null, openElement = '';

$(function(){
	_wrapper = $(".wrapper");

	_window = $(window);

	nie.define(function() {
		var share = nie.require("nie.util.shareV5"),
            PopDialog = nie.require("nie.util.PopDialog"),
			lightbox = nie.require("ui.lightBox");

		share({
			fat: '#NIE-share',
			type: 1,
			defShow: [23 ,22 ,2 ,1 , 24],
			title: $('#share_title').html(),
			img: $('#share_pic').attr('src'),
			url: location.href,
			content: $('#share_desc').html(),
			product: $('#share_product').html()
		});

		$('.light-box').lightBox();

        $('.waiting').click(function() {
        	PopDialog.Alert('敬请期待');
        });
	});

	if (_wrapper.hasClass('wrapper2')) {
		var $tab = $(".tab a").not(".waiting");
		var $tabPage = $(".tab-content .tab-page");
        var $gototop = $('.gototop');

        $tab.click(function () {
			var $this = $(this);
			var index = $this.index();

			if (!$this.hasClass("current")) {
				$tab.removeClass("current");
				$this.addClass("current");
				$tabPage.hide().eq(index).show();
			}
        })

		_window.scroll(function () {
			var top = $(this).scrollTop();

			if (top > 700) {
				$gototop.fadeIn();
			} else {
				$gototop.fadeOut();
			}
		})

		$gototop.click(function(){
			$("html, body").animate({scrollTop: 0}, 500);
		});
        nie.config.copyRight.setWhite();
	} else {
        nie.config.copyRight.setWhite();
	}
});

function getQuery() {
    var obj = {};
    var search = location.search;
    var key, len, i;
	search = search.indexOf('?') !== -1 ? search.substr(1) : search;
	if (!search.length) {
        return null;
	}
	search = search.split('&');
	len = search.length;
	for (i = 0; i < len; i++) {
        search[i] = $.trim(search[i]);
		if (search[i].length) {
			str = search[i].split('=');
			if (str.length == 2) {
				obj[str[0]] = decodeURI(str[1]);
			}
		}
	}
	return obj;
}

function popOpen(obj){
	openElement = obj;
	$(obj).fadeIn(400);
	$("#fade").show().animate({opacity:0.7},400);
	setPos(obj);
}

function popClose(){
	openElement = '';
	$("#fade,.pop").fadeOut(400);
}

function setPos(e){
	var obj = $(e), left, top;
	var _doc = $(document);
	var win = {
			width: _window.width(),
			height: _window.height()
		},
		wrap = {
			width: _wrapper.width()
		},
		doc = {
			width: _doc.width(),
			height: _doc.height()
		};

	var w = wrap.width > win.width ? wrap.width : win.width;
	var h = doc.height > win.height ? doc.height : win.height;

	top = (win.height-obj.outerHeight())/2;
	top = top < 0 ? 0 : top;
	obj.css({"top": top});
	$("#fade").css({"width": w, "height": h});
}
